package com.ihr360.cnb.module.insurance.controller;

/**
 * @author Stone.Shi
 * @description
 * @date 2018-05-25 12:03:33.
 */

import com.ihr360.cnb.module.insurance.model.StaffDataAuthorityCodeConstants;
import com.ihr360.cnb.module.insurance.service.CompanyBenefitAggregateService;
import com.ihr360.commons.model.type.BenefitCategory;
import com.ihr360.commons.vo.PageData;
import com.ihr360.insurance.entity.request.StaffBenefitRequest;
import com.ihr360.insurance.entity.vo.SingleStaffBenefitVo;
import com.ihr360.insurance.entity.vo.StaffBenefitVo;
import com.ihr360.maven.plugin.ModuleCodeStore;
import com.ihr360.maven.plugin.annotation.FunctionDefinition;
import com.ihr360.maven.plugin.annotation.ModuleDefinition;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/companyBenefits")
@ModuleDefinition(mainModuleCode = ModuleCodeStore.Module.BENEFIT_CODE,
        mainModuleName = ModuleCodeStore.Module.BENEFIT_NAME,
        subModuleCode = ModuleCodeStore.Module.Benefit.MANDATORY_CODE,
        subModuleName = ModuleCodeStore.Module.Benefit.MANDATORY_NAME)
public class CompanyBenefitAggregateController {

    @Autowired
    private CompanyBenefitAggregateService companyBenefitAggregateService;

    //社保公积金方案权限code

    @FunctionDefinition(functionName = "已关联社保公积金方案的人数", functionCode = ModuleCodeStore.Function.VIEW)
    @RequestMapping(value = "/count/related", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
    public int getRelatedStaffCount(@RequestParam String companyId,
                                    @RequestParam String userId,
                                    @RequestParam BenefitCategory category) {
        return companyBenefitAggregateService.getRelatedStaffCount(companyId, userId, category, StaffDataAuthorityCodeConstants.ARCHIVE_AUTHORITY_CODE_VIEW);
    }

    @FunctionDefinition(functionName = "未关联社保公积金方案的人数", functionCode = ModuleCodeStore.Function.VIEW)
    @RequestMapping(value = "/count/unRelated", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
    public int getUnRelatedStaffCount(@RequestParam String companyId,
                                      @RequestParam String userId,
                                      @RequestParam BenefitCategory category) {
        return companyBenefitAggregateService.getUnRelatedStaffCount(companyId, userId, category, StaffDataAuthorityCodeConstants.ARCHIVE_AUTHORITY_CODE_VIEW);
    }

    @FunctionDefinition(functionName = "获取未关联社保/公积金方案的员工数据", functionCode = ModuleCodeStore.Function.RELATE)
    @RequestMapping(value = "/getAddList", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
    public PageData<StaffBenefitVo> getUnrelatedStaffs(@RequestParam String companyId,
                                                       @RequestParam String userId,
                                                       @RequestBody StaffBenefitRequest req) {
        return companyBenefitAggregateService.getUnrelatedStaffs(companyId, userId, req, StaffDataAuthorityCodeConstants.ARCHIVE_AUTHORITY_CODE_VIEW);
    }

    @FunctionDefinition(functionName = "将员工关联到方案", functionCode = ModuleCodeStore.Function.RELATE)
    @RequestMapping(value = "/relate", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
    public boolean relateStaff(@RequestParam String companyId,
                               @RequestParam String userId,
                               @RequestBody List<StaffBenefitVo> benefitVos,
                               @RequestParam BenefitCategory category) {
        companyBenefitAggregateService.saveBenefits(companyId, userId, benefitVos, category, StaffDataAuthorityCodeConstants.ARCHIVE_AUTHORITY_CODE_VIEW);
        return true;
    }

    @FunctionDefinition(functionName = "将员工添加到社保或者公积金方案中", functionCode = ModuleCodeStore.Function.RELATE)
    @RequestMapping(value = "/add", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
    public boolean addStaffBenefit(@RequestParam String companyId,
                                   @RequestParam String userId,
                                   @RequestBody List<SingleStaffBenefitVo> singleBenefitVos,
                                   @RequestParam BenefitCategory category) {
        companyBenefitAggregateService.saveSingleBenefits(companyId, userId, singleBenefitVos, category, StaffDataAuthorityCodeConstants.ARCHIVE_AUTHORITY_CODE_VIEW);
        return true;
    }

    @FunctionDefinition(functionName = "更新员工的社保或者公积金数据", functionCode = ModuleCodeStore.Function.RELATE)
    @RequestMapping(value = "/update", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
    public boolean updateStaffBenefit(@RequestParam String companyId,
                                      @RequestParam String userId,
                                      @RequestBody List<SingleStaffBenefitVo> singleBenefitVos,
                                      @RequestParam BenefitCategory category) {
        companyBenefitAggregateService.saveSingleBenefits(companyId, userId, singleBenefitVos, category, StaffDataAuthorityCodeConstants.ARCHIVE_AUTHORITY_CODE_VIEW);
        return true;
    }

    @FunctionDefinition(functionName = "将员工从社保或者公积金方案中移除", functionCode = ModuleCodeStore.Function.RELATE)
    @RequestMapping(value = "/delete", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
    public boolean deleteStaffBenefit(@RequestParam String companyId,
                                      @RequestParam String userId,
                                      @RequestBody List<SingleStaffBenefitVo> singleBenefitVos,
                                      @RequestParam BenefitCategory category) {
        companyBenefitAggregateService.deleteSingleBenefits(companyId, userId, singleBenefitVos, category, StaffDataAuthorityCodeConstants.ARCHIVE_AUTHORITY_CODE_VIEW);
        return true;
    }
}
